home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
apps
/
xconf
/
ConfText.c++
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
136 lines
/*
* Copyright 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
// unix includes
#include <stdio.h>
#include <malloc.h>
#include <string.h>
// conf includes
#include "ConfText.h"
#pragma linkage C
#include <X11/Xatom.h>
extern void _XmTextDisableRedisplay(XmTextWidget widget,
Boolean losesbackingstore);
extern void _XmTextEnableRedisplay(XmTextWidget widget);
#pragma linkage
///////////////////////////////////////////////////////////////////////////////
ConfText::ConfText(Widget text, const char *prompt)
{
_text = text;
if(prompt) {
_prompt = strdup(prompt);
_promptSize = sizeof(prompt);
} else {
_prompt = strdup("");
_promptSize = 0;
}
_buffer = (char *) malloc(MAX_BUF_SIZE);
_ignoreVerify = False;
_lineCount = 0;
prepTextWidget();
}
ConfText::~ConfText()
{
free(_prompt);
free(_buffer);
}
///////////////////////////////////////////////////////////////////////////////
void ConfText::prepTextWidget()
{
Arg args[4]; // make sure this is large enough
int n = 0;
XtSetArg(args[n], XmNautoShowCursorPosition, False); n++;
XtSetArg(args[n], XmNcursorPositionVisible, False); n++;
XtSetArg(args[n], XmNverifyBell, False); n++;
XtSetArg(args[n], XmNuserData, this); n++;
XtSetValues(_text, args, n);
}
void ConfText::clearHistory()
{
_ignoreVerify = True;
XmTextSetString(_text, "");
_ignoreVerify = False;
}
void ConfText::putStr(char *str, Boolean hilite)
{
Arg args[2]; // make sure this is large enough
char buf[MAX_BUF_SIZE];
int textwidth = strlen(str);
strcpy(buf, str);
strcat(buf, "\n");
_ignoreVerify = True;
XmTextPosition last = XmTextGetLastPosition(_text);
XmTextInsert(_text, last, buf);
if(_promptSize > 0) {
XmTextInsert(_text, last, _prompt);
last = last + _promptSize;
XmTextInsert(_text, last, buf);
}
_ignoreVerify = False;
XmTextSetInsertionPosition(_text, last + _promptSize + textwidth);
// scroll if nescessary
short rows;
XtSetArg(args[0], XmNrows, &rows);
XtGetValues(_text, args, 1);
short cols;
XtSetArg(args[0], XmNcolumns, &cols);
XtGetValues(_text, args, 1);
int cnt = (((textwidth - 1) / cols) + 1);
if(_lineCount < (rows - 1)) {
_lineCount = _lineCount + cnt;
}
else {
XmTextScroll(_text, cnt);
}
if(hilite) {
XmTextPosition end = XmTextGetLastPosition(_text);
XmTextSetHighlight(_text, last, end, XmHIGHLIGHT_SELECTED);
}
}
void ConfText::putChr(char ch)
{
char str[2];
str[0] = ch;
str[1] = '\0';
putStr(str);
}
///////////////////////////////////////////////////////////////////////////////